package com.ldy.chapter15;


abstract class GenericWithCreate<T> {
    final T elemet;

    public GenericWithCreate() {
        this.elemet = crete();
    }

    protected abstract T crete();
}

class X{
}

class Creator extends GenericWithCreate<X>{

    @Override
    protected X crete() {
        return new X();
    }
    void f(){
        System.out.println(elemet.getClass().getSimpleName());
    }
}

class Factory{
    static <T> T newInstance(Class<T> clazz) throws IllegalAccessException, InstantiationException {
        return (T)clazz.newInstance();
    }
}

public class CreatorGeneric{
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        final Creator creator = new Creator();
        creator.f();
        Object o = Factory.newInstance(Class.forName("com.ldy.chapter15.X"));

    }
}
